12. Your First Queries in SQL Workspace

The Udacity SQL Workspace Environment

Below you can see a SQL workspace, which we will use frequently from here on, where you can practice writing SQL queries in the classroom.
Here is a short tutorial video on using the SQL Workspace, and Udacity Workspace environments in general.

Intro To SQL Workspaces

Code

If you need a code on the https://github.com/udacity.

Your First SQL Statement

To get started, try using the right panel in the SQL workspace above to type in and evaluate the query (shown again below) that you saw in the previous video. You can begin typing right next to the number 1.

SELECT *
FROM orders;

Once you have typed in your SQL code, you can click on the blue EVALUATE button to run the query. This may take a moment. An alternative to clicking EVALUATE is to use control + Enter to execute your query. If you get an error, it will sometimes cover the EVALUATE button, so this second option is very nice!

You will notice that your instructor Derek uses "demo" tables, like FROM demo.orders (and he will continue to do this in future lessons), but you should write your queries using the table names exactly as shown in the Schema on the left, with "demo" removed, like FROM orders.

SELECT and FROM in Every SQL Query

Every query will have at least a SELECT and FROM statement. The SELECT statement is where you put the columns for which you would like to show the data. The FROM statement is where you put the tables from which you would like to pull data.

Your Turn

Try writing your own query to select only the id, account_id, and occurred_at columns for all orders in the orders table.

Checking the Output of your Query

If you see an error message after executing your query, no problem! Programmers get errors all the time! Mistakes are opportunities to learn. :)

Just take a look at what the error says, check the syntax of your query compared to your notes or what was shown in the lesson video or text, make revisions, and try it again. See what you can learn from your mistake, and make a note about it.

If you see a message saying "Success!" this means you had no syntax errors and your query executed well. It does not necessarily mean that you got your desired results though! It is still up to you to examine your output and see if what you got was what you wanted.

You can also check on the next page after each quiz, to see how your query compares to the solution that we provide. We highly recommend that you try writing your query first, before looking at any solution. :)

Downloading the Schema Tables

(In some versions of this lesson, you might be able to download the Parch & Posey database to your computer from the Resources tab in the left sidebar of your classroom, but this is not necessary for you to do at all.)

Code

If you need a code on the https://github.com/udacity.